<template>
  <el-dialog
    title="匹配结果"
    :visible.sync="visible"
    width="400px"
  >
    <el-row>
      <el-col :span="7">总人数</el-col>
      <el-col :span="3" class="number">{{result.totalNum}}</el-col>
    </el-row>
    <el-row>
      <el-col :span="7">匹配成功人数</el-col>
      <el-col :span="3" class="number">{{result.matchingNum}}</el-col>
      <el-col :span="4" v-if="result.matchingNum > 0">
        <el-button type="text" @click="onDownloadClick(1)">下载文件</el-button>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="7">匹配失败人数</el-col>
      <el-col :span="3" class="number">{{result.mismatchingNum}}</el-col>
      <el-col :span="4" v-if="result.mismatchingNum > 0">
        <el-button type="text" @click="onDownloadClick(0)">下载文件</el-button>
      </el-col>
    </el-row>
    <span slot="footer">
      <el-button type="primary" @click="visible = false">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      result: {},
      visible: false
    };
  },
  methods: {
    show(result, file) {
      this.visible = true;
      this.result = result;
      this.file = file;
    },
    async onDownloadClick(type) {
      let formData = new FormData();
      formData.append('file', this.file);
      formData.append('type', type);
      let response = await this.$http.create().post('/api/grant/batch/downloadMatchResult', formData, {
        responseType: 'arraybuffer'
      });
      let blod = new Blob([response.data], {type: 'application/vnd.ms-excel;charset=utf-8'});
      window.location.href = URL.createObjectURL(blod);
    }
  },
}
</script>

<style scoped>
.el-row {
  line-height: 48px;
}
.el-col.number {
  font-weight: bold;
}
</style>